using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class DividerHandler : LightRayHandler {

	private bool isTriggered = false;
	
	public override void initialize(int id, Vector3 position, float rotation, Color c, bool fixedObj){
		Type = ObjectType.Divider;
		
		LevelConstants.nbDivider++;
		
		base.initialize(id, position, rotation, c, fixedObj);
	}
	
	public override List<LightHitInfo> getNextLightRay(LightHitInfo hitInfo){
		List<LightHitInfo> newRays = new List<LightHitInfo>();
		
		
		if(!isTriggered){
			List<Color> colors = ColorUtils.getPrimaryComponents(hitInfo.LightColor);
			foreach(Color c in colors){
				LightHitInfo newRay = new LightHitInfo(hitInfo);
				newRay.Point = transform.position;
				newRay.LightColor = c;
				
				newRays.Add(newRay);
			}
			
			if(colors.Count == 2){
				LightHitInfo newRay = new LightHitInfo(hitInfo);
				newRay.Point = transform.position;
				newRays.Add(newRay);
			}
			
			if(newRays.Count >= 2){
				newRays[0].Direction = Quaternion.AngleAxis(90,Vector3.forward) * newRays[0].Direction;
				newRays[1].Direction = Quaternion.AngleAxis(-90,Vector3.forward) * newRays[1].Direction;
			}
			
			isTriggered = true;
		}else{
			hitInfo.Direction = Vector3.zero;
			newRays.Add(hitInfo);
		}
		
		return newRays;	
	}
	
	void LateUpdate(){
		isTriggered = false;	
	}
	
	void OnDestroy(){
		LevelConstants.nbDivider--;	
	}
}